﻿#ifndef RECIVEDATABUFFER_H
#define RECIVEDATABUFFER_H
//
#include <mutex>

#define CHANNEL_COUNT 10    // 通道数
#define BUFFER_SIZE 10240   // 缓存大小

typedef struct
{
    int channelId ;
    int dataLen ;
    unsigned char dataBuf[BUFFER_SIZE] ;
} DATABUFFER;


class ReciveDataBuffer
{
public:
    static ReciveDataBuffer& getInstance();

    ReciveDataBuffer(ReciveDataBuffer&)=delete;
    ReciveDataBuffer& operator=(const ReciveDataBuffer&)=delete;
    ~ReciveDataBuffer() = default;

    // 写入buffer
    bool writeDataToBuffer(int channelIndex, char *buf, int len);
    // 写回到buffer头部
    bool writeBackDataToBuff(int channelIndex, char *buf, int len);
    // 一次性取完数据
    bool readDataFromBuffer(int channelIndex, char *buf, int bufLength, int &getLength);
private:
    // 私有构造
    ReciveDataBuffer();
private:
    std::mutex m_mutex;
    // 多通道缓存
    DATABUFFER m_recvBuffer[CHANNEL_COUNT];

	
};

#endif
